// subPackages/packageA/operatingRisk/seriousIllegality/seriousIllegality.ts
import { ZCC_TYPE } from "../../../../../typings/types/common";
import { Operation } from "../../../../../typings/types/operation";
import { getSeriousIllegalityListAPI } from "../../api/operatingRisk";
import { ZCC } from "../../../../utils/BasePage";

interface PageData {
  companyId: string
}
new ZCC.RefreshListPage<any>({

  onClick() {

  },
  async getListDatas() {
    const that = this
    this.setRefreshing()
    try {
      const res = await getSeriousIllegalityListAPI(this.data.companyId, this.data.page)
      if (res.content) {
        console.log(res.content)
        let tmp = this.processListDatas(res.content)
        that.updateDatasWithNewItems(tmp, res.content.total, res.content.hasNextPage)
      }
    } finally {
      that.endRefreshing()
    }
  },
  processListDatas(content: ZCC_TYPE.ListResult<Operation.SeriousIllegalityList>) {

    const cells = content.list.flatMap((item: Operation.SeriousIllegalityList) => {

      let tmp = [
        [
          { title: '类别：', val: item.type, ishorizontal: true },
          { title: '列入严重违法失信企业名单原因：', val: item.addReason, ishorizontal: false },
          { title: '列入决定机关：', val: item.addOffice, ishorizontal: true },
          { title: '列入时间：', val: item.addDate, ishorizontal: true },
          { title: '移出严重违法失信企业名单原因：', val: item.removeReason, ishorizontal: false },
          { title: '移出决定机关：', val: item.removeOffice, ishorizontal: true },
        ]
      ]

      return tmp
    })
    return cells
  },
  /**
   * 页面的初始数据
   */
  data: <PageData>{
    companyId: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.setData({
      companyId: this.options.companyId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getListDatas()
  },

  onPullDownRefresh() {
    if (this.resetPageIfNeed()) {
      this.getListDatas()
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.getListDatas()
  },
})